/*
 * @Author: 涵崽
 * @Date: 2023-12-12 09:00:13
 * @email: 1045654@qq.com
 * @gitee: https://gitee.com/han-zai
 * @LastEditors: 涵崽
 * @LastEditTime: 2023-12-12 16:04:07
 * @Description: 微信：1045654
 *
 * 传递一个值时，参数默认为type值。
 * 传递两个值时，则正常
 * 没传递值时，默认返回当前时间，type值默认为0
 *
 */

export function formatTime(value, type = 0) {
  var time = new Date();
  if (arguments.length == 1) {
    tyle = arguments[0];
  } else if (arguments.length == 2) {
    time = new Date(value);
  }
  var year = time.getFullYear();
  var month = time.getMonth() + 1;
  var date = time.getDate();
  var hour = time.getHours();
  var minute = time.getMinutes();
  var second = time.getSeconds();
  month = month < 10 ? "0" + month : month;
  date = date < 10 ? "0" + date : date;
  hour = hour < 10 ? "0" + hour : hour;
  minute = minute < 10 ? "0" + minute : minute;
  second = second < 10 ? "0" + second : second;
  var arr = [
    year + "-" + month + "-" + date,
    year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second,
    year + "年" + month + "月" + date,
    year +
      "年" +
      month +
      "月" +
      date +
      " " +
      hour +
      ":" +
      minute +
      ":" +
      second,
    hour + ":" + minute + ":" + second,
    month + "-" + date,
    year + "-" + month + "-" + date + " " + hour + ":" + minute,
  ];
  return arr[type];
}
